import type { PDataRes, PListRes } from "@/api/response";
import type { SysMenu } from "../../admin/api/sysMenu";
import { http } from "@/utils/http";

export type LoginResp = {
  code: number;
  token: string;
  msg: string;
  expire: number;
};

export type SessionInfo = {
  userId: string;
  userName: string;
  roleId: string;
  deptId: string;
  tenantId: string;
  ip: string;
  loginAt: string;
  expire: number;
};

export const getSessionMenu = (): Promise<PListRes<SysMenu>> => {
  return http.get("/api/v1/session/menus");
};

export const getSessionInfo = (): Promise<PDataRes<SessionInfo>> => {
  return http.get("/api/v1/session/info");
};

export const getCaptcha = (): Promise<
  PDataRes<{ uuid: string; img: string }>
> => {
  return http.get("/api/v1/session/captcha");
};

export const doLogin = (data: {
  username: string;
  password: string;
  captcha: string;
  uuid: string;
}): Promise<LoginResp> => {
  return http.post("/api/v1/session/login", { data });
};

export const refreshToken = (): Promise<LoginResp> => {
  return http.post("/api/v1/session/refresh");
};
